//
//  UrbanNewsTableViewCell.m
//  UrbanManagement
//
//  Created by Can on 18/4/12.
//  Copyright © 2018年 hwd. All rights reserved.
//

#import "UrbanNewsTableViewCell.h"

@interface UrbanNewsTableViewCell ()
{
    CGFloat h;
}

@end

@implementation UrbanNewsTableViewCell

// 1. 初始化子视图
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
    }
    
    return self;
}

- (void)loadData:(NSDictionary *)data{
    
    for (UIView *subView in self.contentView.subviews)
    {
        [subView removeFromSuperview];
    }
    
    //消息title
    UILabel *lable = [TomamaUI createLabel:CGRectMake(16*screenW_6, 23*screenW_6, SCREENW - 16*screenW_6 - 95/2*screenW_6, 15*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:15*screenW_6] textColor:Color(51, 51, 51) text:[data objectForKey:@"newsTitle"]];
    lable.frame = CGRectMake(16*screenW_6, 23*screenW_6, SCREENW - 16*screenW_6 - 95/2*screenW_6, [self lableHeight:lable]);
    [self.contentView addSubview:lable];
    
    //右侧图标
    UIImageView *imageView = [TomamaUI createImageView:CGRectMake(CGRectGetMaxX(lable.frame) + 25*screenW_6, 0, 7*screenW_6, 12*screenW_6) backGroundImageV:@"right_arrow"];
    [self.contentView addSubview:imageView];
    imageView.center = CGPointMake(imageView.center.x, lable.center.y);
    
    h = CGRectGetMaxY(lable.frame) + 23*screenW_6;
}

- (CGFloat)lableHeight:(UILabel *)lable{
    lable.numberOfLines = 0;//根据最大行数需求来设置
    lable.lineBreakMode = NSLineBreakByTruncatingTail;
    CGSize maximumLabelSize = CGSizeMake(SCREENW - 54*screenW_6, 9999);//labelsize的最大值
    //关键语句
    CGSize expectSize = [lable sizeThatFits:maximumLabelSize];
    return expectSize.height;
}

- (CGFloat)height
{
    return h;
}

+ (CGFloat)cellHeight:(NSDictionary *)data
{
    UrbanNewsTableViewCell *cell = [[UrbanNewsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"AdvisoryCell"];
    [cell loadData:data];
    return [cell height];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
